package com.itggm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itggm.Result.ResponseResult;
import com.itggm.dto.SchedulePageDTO;
import com.itggm.pojo.Schedule;
import com.itggm.service.ScheduleService;
import com.itggm.mapper.ScheduleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author root
* @description 针对表【sys_schedule】的数据库操作Service实现
* @createDate 2025-01-02 08:10:43
*/
@Service
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule> implements ScheduleService{
    @Override
    public ResponseResult schedulePage(SchedulePageDTO schedulePageDTO) {
        Page<Schedule> schedulePage = new Page<>(schedulePageDTO.getPage(), schedulePageDTO.getLimit());
        Date classTime = schedulePageDTO.getClassTime();

        LambdaQueryWrapper<Schedule> lambda = new QueryWrapper<Schedule>().lambda();
        lambda.eq(ObjectUtils.isNotNull(classTime),Schedule::getClassTime,classTime)
                .orderByDesc(Schedule::getClassTime);

        baseMapper.selectPage(schedulePage,lambda);


        return ResponseResult.success().data("total",schedulePage.getTotal())
                .data("tableData",schedulePage.getRecords());
    }
}




